apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: ${info.name}
  namespace: ${info.namespace}
<#if info.resourceVersion??>
  resourceVersion: "${info.resourceVersion}"
</#if>
spec:
  hosts:
  - ${info.domain}
<#if info.gatewayName??>
  gateways:
  - ${info.gatewayName}
</#if>
  http:
<#list info.matchs as item>
  <#if info.gatewayName??>
  - match:
    - uri:
        prefix: ${item.requestPath}
    <#if item.hasHeader()>
      headers:
        ${item.headerKey}:
          exact: "${item.headerValue}"
    </#if>
    rewrite:
      uri: ${item.appPath}
    route:
    <#list item.route as rItem>
    - destination:
        host: ${rItem.host}
    <#if rItem.subset??>
        subset: "${rItem.subset}"
    <#else>
        port:
          number: ${rItem.port?c}
    </#if>
    <#if rItem.weight??>
      weight: ${rItem.weight}
    </#if>
    </#list>
  <#else>
  - match:
    <#if item.hasHeader()>
    - headers:
        ${item.headerKey}:
          exact: "${item.headerValue}"
    </#if>
    route:
    <#list item.route as rItem>
    - destination:
        host: ${rItem.host}
    <#if rItem.subset??>
        subset: "${rItem.subset}"
    <#else>
        port:
          number: ${rItem.port?c}
    </#if>
    <#if rItem.weight??>
      weight: ${rItem.weight}
    </#if>
    </#list>
  </#if>
</#list>
